/**
 * @author liubaohui
 * @desc 获取字典项的几种方式
 */
export default {
  // 获取字典项
  getDict: state => (dictName) => state.dict[dictName].labels || [],
  // 获取添加全部的字典项
  dictAddAll: state => (dictName) => {
    let labels = state.dict[dictName].labels || []
    return labels.length > 0 ? [{id: '', label: '全部'}, ...labels] : labels
  },
  /**
   * @desc 根据value过滤掉需要的字典项
   * @example
   *  // 获取可搜索的周转进度状态：“待开工”、“生产中”、“已完工”
   *  partBatchProcessStatus() {
   *     return this.$store.getters.filterDictByValues('batchProcessStatus', ['ToBeStarted', 'Producing', 'Finished'])
   *  }
   */
  filterDictByValues: state => (dictName, list) => {
    let labels = state.dict[dictName].labels || []
    return labels.filter(item => list.includes(item.value))
  }
}
